package org.googlecode.lightning.search.utils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.StringUtils;

/**
 * 
 * @author daragon
 * 
 */
public class FileRecogizer {

	private Map<String, String> mimeTypes;

	/**
	 * 
	 * @param path
	 * @return
	 * @throws IOException
	 */
	public String getMimeTypeByExtension(String name) {
		String mimeType = null;

		String ext = StringUtils.substringAfterLast(name, ".");

		if ("".equals(ext)) {
			return mimeType;
		}
		Set<String> keySet = mimeTypes.keySet();
		for (String key : keySet) {
			if (StringUtils.containsIgnoreCase(key, ext)) {
				return mimeTypes.get(key);
			}
		}
		return mimeType;
	}

	public void setMimeTypes(Map<String, String> mimeTypes) {
		this.mimeTypes = mimeTypes;
	}

}
